<include file="Base/header" /> 	
<link href="__PUBLIC__/chosen/chosen.css" rel="stylesheet" />
<script src="__PUBLIC__/chosen/chosen.jquery.js"></script>  
<div class="page-container">
	<include file="Base/menu" /> 
	<div class="page-content">
		<div class="container-fluid">
			<div class="row-fluid">
					<div class="span12"> 
						<!-- BEGIN PAGE TITLE & BREADCRUMB-->
						<h3 class="page-title">
						</h3>
						<ul class="breadcrumb">
							<li>
								<i class="icon-home"></i>
								<a href="/index.php/Admin/">首页</a> 
								<i class="icon-angle-right"></i>
							</li>
							<li><a href="/index.php/Admin/Other">工具</a></li>
						</ul>
						<!-- END PAGE TITLE & BREADCRUMB-->
					</div>
			</div>
			<div class="row-fluid">
					<div class="span12">
						<!-- BEGIN EXAMPLE TABLE PORTLET-->
						<div class="portlet box blue">
							<div class="portlet-title">
								<div class="caption"><i class="icon-globe"></i>机械捕鼠器记录表</div>
								<div class="tools">
									<a href="javascript:;" class="collapse"></a>
									<a href="javascript:;" class="reload"></a>
									<a href="javascript:;" class="remove"></a>
								</div>
							</div>
							<div class="portlet-body">
                                <div class="clearfix">
                                    <div class="btn-group">
                                        <a href="__MODULE__/Export/MouseIron?begin_time={$begin_time|default=''|date='Y-m-d',###}&end_time={$end_time|default=''|date='Y-m-d',###}"><button id="sample_editable_1_new" class="btn green">
                                        设备维度导出&nbsp;&nbsp;<i class="icon-plus"></i>
                                        </button></a>
                                    </div>
                                    <div class="btn-group">
                                        <a href="__MODULE__/Export/MouseIrons?begin_time={$begin_time|default=''|date='Y-m-d',###}&end_time={$end_time|default=''|date='Y-m-d',###}&shop_id={$shop_id}&type=2">
                                        <button id="sample_editable_1_new" class="btn green">
                                        月份维度导出&nbsp;&nbsp;<i class="icon-plus"></i>
                                        </button></a>
                                    </div>
                                </div>                                
                                <div id="sample_1_wrapper" class="dataTables_wrapper form-inline" role="grid">
                                <div class="row-fluid">
                                    <form method="get" action="__URL__/MouseIron" >
                                    <div class="span3">
                                        <div id="sample_1_length" class="dataTables_length">
                                                <select size="1" id="mySelect" name="page_size" aria-controls="sample_1" class="m-wrap small" onchange="submit(this.value)">
                                                    <option id="page10" value="10">10</option>
                                                    <option id="page20" value="20">20</option>
                                                    <option id="page50" value="50">50</option>
                                                    <option id="page100" value="100">100</option>
                                                </select> 条/每页</label>
                                            </div>
                                        </div>
                                        <div class="span3">
                                            <div class="dataTables_filter" id="sample_1_filter">
                                                客户：</label>
                                                <select name="shop_id" id="sum_shop_id" aria-controls="sample_1" class="m-wrap small shopId">
                                                     <option>=请选择=</option>
                                                    <foreach name="shop" item="v">
                                                        <option value="{$v['id']}" <if condition="$v['id'] eq $shop_id">selected=selected</if>>{$v['shop_name']}</option>
                                                    </foreach>
                                                </select>
                                                
                                            </div>
                                        </div>

                                    <script>
                                        $(".shopId").chosen({
                                            search_contains: true,
                                            no_results_text: "没有找到",
                                        });
                                    </script>
                                    <div class="span6">
                                        <div class="dataTables_filter" id="sample_1_filter">
                                            <label>
                                                <input class="m-wrap medium" id="start-time" value="{$begin_time|default=''|date='Y-m-d',###}" name="begin_time" placeholder="开始日" onclick="laydate()">
                                                <input class="m-wrap medium" id="end-time" value="{$end_time|default=''|date='Y-m-d',###}" name="end_time" placeholder="截止日" onclick="laydate()">
                                                <button onclick="shousuos()" class="green">搜索</button>
                                            </label>
                                        </div>
                                    </div>
                                    </form>
                                </div>
<table class="table table-striped table-bordered table-hover dataTable" id="sample_1" aria-describedby="sample_1_info">
    <thead>
        <tr role="row">
            
            <th class="hidden-480 sorting_disabled" role="columnheader" rowspan="1"
            colspan="1" aria-label="Email" style="width: 40px;">
                GL编号
            </th>
            
            <th class="hidden-480 sorting" role="columnheader" tabindex="0" aria-controls="sample_1"
            rowspan="1" colspan="1" aria-label="" style="width: 40px;">
                地点
            </th>
            <th class="hidden-480 sorting" role="columnheader" tabindex="0" aria-controls="sample_1"
            rowspan="1" colspan="1" aria-label="" style="width: 40px;">
                小家鼠
            </th>
            <th class="hidden-480 sorting" role="columnheader" tabindex="0" aria-controls="sample_1"
            rowspan="1" colspan="1" aria-label="" style="width: 40px;">
                褐家鼠
            </th>
            <th class="hidden-480 sorting" role="columnheader" tabindex="0" aria-controls="sample_1"
            rowspan="1" colspan="1" style="width: 40px;">
                黄胸鼠
            </th>
            <th class="hidden-480 sorting" role="columnheader" tabindex="0" aria-controls="sample_1"
            rowspan="1" colspan="1" style="width: 40px;">
                其他
            </th>
            <th class="hidden-480 sorting" role="columnheader" tabindex="0" aria-controls="sample_1"
            rowspan="1" colspan="1" style="width: 40px;">
                总数
            </th>
            <th class="hidden-480" role="columnheader" tabindex="0" aria-controls="sample_1"
            rowspan="1" colspan="1" style="width: 40px;">
                总结
            </th>
            <th class="hidden-480" role="columnheader" tabindex="0" aria-controls="sample_1"
            rowspan="1" colspan="1" style="width: 40px;">
                搜总结
            </th>
            <th class="hidden-480 sorting_disabled" role="columnheader" rowspan="1"
           colspan="1" aria-label="Joined" style="width: 50px;">
               管理
            </th> 
        </tr>
    </thead>
    <tbody role="alert" aria-live="polite" aria-relevant="all">
    <foreach name="data" item="vo"> 
     <tr class="gradeX odd">
        <td class="hidden-480">{$vo.id}</td>
        <td class="hidden-480">{$vo.area}</td>
        <td class="hidden-480" cate-id="6" data-v="{$vo.smallmouse}">{$vo.smallmouse}</td>
        <td class="hidden-480" cate-id="7" data-v="{$vo.hemouse}">{$vo.hemouse}</td>
        <td class="hidden-480" cate-id="8" data-v="{$vo.humouse}">{$vo.humouse}</td>
        <td class="hidden-480" cate-id="5" data-v="{$vo.other}">{$vo.other}</td>
        <td class="hidden-480">{$vo.sum}</td>
        <td class="hidden-480"><input class="zongjie{$vo.id}" value="" style="width:70px !important;" ></td>
        <td class="hidden-480 "><input class="key{$vo.id}" value="" style="width:60px !important;" ><a onclick="search_one(this)" href="javascript:;" data-class="zongjie{$vo.id}" data-key="key{$vo.id}">搜索</a></td>
        <td class="hidden-480 "><a class="edit" onclick="edittable(this)" href="javascript:;">编辑</a></td>
        </tr>
    </foreach>
    </tbody>
</table>
<div class="dataTables_length" id="sample_1_length">
    <label>
        <input placeholder="总结：" id="search" name="user_name" type="text" class="m-wrap medium">
        <button onclick="shousuo()" class="btn green">搜索&nbsp;&nbsp;<i class="icon-plus"></i></button>
        <button onclick="baocun()" class="btn green">保存&nbsp;&nbsp;</button>
    </label>
</div>
<div class="controls">
    <textarea class="span10 m-wrap" rows="3" id="buttons">总结:</textarea>
</div>
<!-- 分页 -->
<div class="row-fluid">
    <div class="span6">
        <div class="dataTables_info" id="sample_1_info">
          共{$count}条数据记录。
        </div>
    </div>
    <div class="span6">
        <div class="dataTables_paginate paging_bootstrap pagination">
            {$page}
        </div>
    </div>
</div>								
								</div>
							</div>
						</div>
						<!-- END EXAMPLE TABLE PORTLET-->
					</div>
				</div>
		</div>
	</div>
</div>
<include file="Base/footer" /> 
<script src="__PUBLIC__/plugins/layer/layer.min.js"></script>
<script src="__PUBLIC__/js/layer/laydate/laydate.js"></script>
<script type="text/javascript">
function del(id){
    $.ajax({
        type:'POST',
        dataType: "json",
        url: "{:U('Admin/Shop/shopDel')}",
        data: {"id":id},
        success:  function(result){
            if(result.status==1){
                layer.alert(result.info,function(){self.location="__MODULE__/Shop/index";});
            }else if(result.status==0){
                //失败
                layer.alert(result.info);
            }
        }
    });
}

</script>
<script type="text/javascript">
    function edittable(obj){
        var tds = $(obj).parent().parent().children();
        var trhtml = $(obj).parent().parent();
        tds[2].innerHTML = '<input type="text" style="width:40px !important; " class="m-wrap small feie" value="' +tds[2].innerHTML+ '">';
        tds[3].innerHTML = '<input type="text" style="width:40px !important;" class="m-wrap small" value="' + tds[3].innerHTML + '">';
        tds[4].innerHTML = '<input type="text" style="width:40px !important;" class="m-wrap small" value="' + tds[4].innerHTML + '">';
        tds[5].innerHTML = '<input type="text" style="width:40px !important;" class="m-wrap small" value="' + tds[5].innerHTML + '">';
        tds[9].innerHTML = '<a class="edit" onclick="savetable(this)" href="javascript:;">保存</a>';
    }
    function savetable(obj){
        var tds = $(obj).parent().parent().children();
        var postData = {};
        postData['start_time'] = $("#start-time").val();
        postData['end_time'] = $("#end-time").val();
        postData['device_id'] = tds[0].innerHTML;
        var animals = new Array(4);
        var sum = 0;
        for(var i = 0;i<4;i++){
            animals[i] = [$(tds[i+2]).attr("cate-id"),$(tds[i+2]).attr("data-v"),$($(tds[i+2]).children()[0]).val()];
            if($($(tds[i+2]).children()[0]).val())
                sum += parseInt($($(tds[i+2]).children()[0]).val());
        }
        postData['animals'] = animals;
        postData['summary'] = $($(tds[7]).children()[0]).val();


        //复制的时候要注意这里有一个类别
        postData['cate'] = 4; /////千万不能忘记
        var url = "{:U('Update/lightUp')}";
         
        $.post(url,postData,function(result){
            
        },"JOSN");
        tds[2].innerHTML = $($(tds[2]).children()[0]).val();
            tds[3].innerHTML = $($(tds[3]).children()[0]).val();
            tds[4].innerHTML = $($(tds[4]).children()[0]).val();
            tds[5].innerHTML = $($(tds[5]).children()[0]).val();
            tds[6].innerHTML = sum;
            tds[9].innerHTML = '<a class="edit" onclick="edittable(this)" href="javascript:;">编辑</a>';
    }
</script>
<script type="text/javascript">
    function search_one(obj){
        var key_class = $(obj).attr("data-key");
        var keywords = $("."+key_class).val();
        var itemClass = $(obj).attr('data-class');
        layer.open({
            type: 2,
            area: ['900px', '600px'],
            fixed: false, //不固定
            maxmin: true,
            content: "__MODULE__/Search/sum_serch?keywords="+keywords +"&itemClass="+ itemClass,
        });
    }

function shousuo(id){
    var keywords = $("#search").val();
    layer.open({
        type: 2,
        area: ['1000px', '700px'],
        fixed: false, //不固定
        maxmin: true,
        content: "__MODULE__/Search/index/keywords/"+keywords,
    });
}
//保存总结
function baocun(){
    var shop_id = $("#sum_shop_id").val();
    if (shop_id == 0 ) {
        alert("请选择客户");
        return false;
    }
    var start_time = $("#start-time").val();    var end_time = $("#end-time").val();
    var content = $("#buttons").val();          var url = "{:U('Update/saveSum')}"
    if(end_time == ""){alert("请选择时间");return false;}
    postData = {
        'shop_id':shop_id,      'start_time':start_time,
        'end_time':end_time,    'cate' : 4,
        'content' : content
    }
    $.post(url,postData,function(result){
        if (result.status == 1) {
            alert("保存成功");
        }
    },"JSON");
}
</script>
<script language="javascript" type="text/javascript">
    function submit(){
        $.ajax({
            type:"get",
            url:"index?page_size",
            async:false,
        })
    }
    element=document.getElementById('page'+{$Think.session.page_size});
    element.setAttribute("selected","selected");
</script>